/*
 * CS_DAILY_REWARD_GACHYA.cpp
 *
 *  Created on: 2013. 9. 5.
 *      Author: the2
 */

#include "../../Command.h"
#include "../../User.h"
#include "../../NLogic/Reward.h"
#include "../../NLogic/Function.h"


namespace ProjectZ { namespace NCommand {
/*
ZNO_CS_DAILY_REWARD_GACHYA		0x2906	///일일 보상 캡슐 뽑기
{

}

ZNO_SC_DAILY_REWARD_GACHYA		0x2907
{
	s16	s16ack;
	u8	u8reward_exists;		//보상여부 (0 : 이미 보상 받음, 1 : 보상 있음)
}
*/
void Command::CS_DAILY_REWARD_GACHYA( User * pUser, ::Network::Packet *pPacket )
{
	PREPARE_PACKET;

	NLogic::Reward::Data * data = pUser->GetReward()->GetData(NLogic::Reward::RewardType::DAILY_PET_REWARD);

	time_t currentTime = NLogic::NFunction::GetDailyInitTime(time(NULL));

	time_t lastLoginTime = pUser->GetUserInfo().array_Slot[static_cast<int>(NLogic::Reward::RewardType::DAILY_PET_REWARD)].reg_date;

	DEBUGLOG("userseq = %d lastLoginTime = %d, currentTime = %d data->_value = %d", pUser->GetUserSeq(), lastLoginTime, currentTime, data->_value);

	if(lastLoginTime < currentTime || 1 == data->_value)
		data->_value = 1;

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << static_cast<int16_t>(ACK_OK)
			<< static_cast<uint8_t>(data->_value);
	pAck->MakePacket(CMD_SC_DAILY_REWARD_GACHYA);
	pUser->Send(pAck);
}


} /*NCommand*/ } /*ProjectZ*/
